<?php
declare (strict_types = 1);

namespace app\command;

use app\model\Device;
use app\model\DeviceRecords;
use app\model\DeviceRent as DeviceRentModel;
use Stomp\Client;
use Stomp\Exception\StompException;
use Stomp\Network\Observer\Exception\HeartbeatException;
use Stomp\Network\Observer\ServerAliveObserver;
use Stomp\StatefulStomp;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
use think\facade\Log;
class DeviceExpirationTime extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('expire_time')
            ->setDescription('the rent command');
    }

    protected function execute(Input $input, Output $output)
    {
        //未激活 已激活 已过期

        $device = Device::where('use_status','已激活')->where('delay_time','<>','0000-00-00 00:00:00')->select();
        writeLog($device);
        foreach ($device as $v){
            if(strtotime($v['delay_time']) < time()){ //设备到期时间 小于当前时间 就是过期了
                $v->save(['use_status'=>'已过期']);
            }
        }

    }

}
